<script>
//给定一个区间的集合，找到需要移除区间的最小数量，使剩余区间互不重叠。
//https://leetcode-cn.com/problems/non-overlapping-intervals/solution/wu-zhong-die-qu-jian-ji-bai-liao-100de-y-kkzr/
var eraseOverlapIntervals = function(intervals) {
    if(intervals.length < 2){return 0}
    intervals.sort((a, b) => a[0] - b[0])
    let end = intervals[0][1]
    let count = 0
    for(let i=1; i<intervals.length; i++){
        if(intervals[i][0] < end){
            end = Math.min(end, intervals[i][1])
            count++
        }else{
            end = intervals[i][1]
        }
    }
    return count
};


</script>